﻿(function($) {
    widgets[2] =
        {
            widgetTypeId: 2,
            optionText: 'Select List',
            valueChanged: function() {
                $("#" + notification.WidgetGuid.replace(/-/g, '')).val(notification.Value);
            },
            getHtml: function(widget) {
                var html = "<select id='" + widget.WidgetGuid.replace(/-/g, '') + "'>";

                if (widget.Values != null) {

                    for (var k = 0; k < widget.Values.length; k++) {
                        var widgetVal = widget.Values[k];

                        html = html + "<option value='" + widgetVal.Value + "' ";

                        if (widgetVal.Value == widget.CurrentValue) {
                            html = html + "selected='true'";
                        }

                        html = html + ">" + widgetVal.Value + "</option>";
                    }
                }

                html = html + "</select>";
                return html;
            },
            widgetReady: function(widget) {
                $('#' + widget.WidgetGuid.replace(/-/g, '')).bind('change', function(event) {
                    $.ajax({
                        type: "GET",
                        url: "/s/changeValue",
                        data: { widgetGuid: $(this).attr('id'), newValue: $(this).val() },
                        success: function(data) {
                            if (!data) {
                                $("#errorMessage").text("Error seting value!");
                                $('#errorPane').makeFloaty({
                                    spacing: 20, time: '1s'
                                });
                            }
                        }
                    });
                });
            }
        };
})(jQuery);